/*
 * @Author: 杨光辉(GerhardYang)
 * @Date: 2021-09-08 13:48:45
 * @LastEditors: 杨光辉(GerhardYang)
 * @LastEditTime: 2021-12-13 12:45:33
 * @Description: file content
 * @Copyright: 超图软件华中平台客户中心 (SuperMap Software Co., Ltd. -Central China Platform)
 */
export default {
  computed: {
    //esURL
    defaultSearchURL() {
      return (
        window.getServiceUrl("", window.servicesPorts.es) +
        "/poi_ik_20211212/_search?type=poi"
      );
    },
    cutWordSearchURL() {
      return (
        window.getServiceUrl("", window.servicesPorts.es) +
        "/poi_standard_20211212/_search?type=poi"
      );
    },
  },
  methods: {
    /**
     * @description: 获取ES查询分类字符
     * @param {*} currentCityCode
     * @param {*} currentCity
     * @return {*}
     */
    getGroupStr(currentCityCode, currentCity) {
      let groupStr = "";
      Number(currentCityCode) % 100 === 0
        ? (groupStr = currentCityCode.slice(0, 4))
        : (groupStr = currentCityCode);
      if (currentCity == "湖南") {
        groupStr = currentCityCode.slice(0, 2);
      }
      return groupStr;
    },
    buildESqueryDataByCutWord(inputStr, groupStr, from = 0, size = 10) {
      let querydata = {
        from: from,
        size: size,
        query: {
          bool: {
            must: [
              {
                query_string: {
                  query: inputStr,
                  analyze_wildcard: false,
                  default_field: "NAME",
                },
              },
              // { match_phrase: { NAME: { query: `${inputStr}**` } } },
              {
                query_string: {
                  query: `${groupStr}**`,
                  analyze_wildcard: false,
                  default_field: "ADMINCODE",
                },
              },
            ],
            should: [],
          },
        },
      };
      // let match_phrase = {
      //   match_phrase: {},
      // };
      // //输入字符串不分词;
      // match_phrase.match_phrase["NAME"] = {};
      // match_phrase.match_phrase["NAME"].query = `${inputStr}`;
      // match_phrase.match_phrase["NAME"].slop = 0;
      // querydata.query.bool.must.push(match_phrase);
      // match_phrase = {
      //   match_phrase: {},
      // };
      // //输入字符串不分词
      // match_phrase.match_phrase["ADDRESS"] = {};
      // match_phrase.match_phrase["ADDRESS"].query = `${inputStr}`;
      // match_phrase.match_phrase["ADDRESS"].slop = 0;
      // querydata.query.bool.must.push(match_phrase);
      // let multi_match = { multi_match: {} };
      // multi_match.multi_match["query"] = inputStr;
      // multi_match.multi_match["fields"] = [`NAME`, "ADDRESS"];
      // multi_match.multi_match["operator"] = "or";
      // multi_match.multi_match["minimum_should_match"] = "100%";
      // querydata.query.bool.must.push(multi_match);
      return querydata;
    },
    /**
     * @description:
     * @param {*} inputStr
     * @param {*} groupStr
     * @param {*} from
     * @param {*} size
     * @return {*}
     */
    buildESqueryData(inputStr, groupStr, from = 0, size = 10) {
      let querydata = {
        from: from,
        size: size,
        query: {
          bool: {
            must: [
              // {
              //   query_string: {
              //     query: inputStr,
              //     analyze_wildcard: false,
              //     default_field: "NAME",
              //   },
              // },
              { match_phrase: { NAME: { query: `${inputStr}**` } } },
              {
                query_string: {
                  query: `${groupStr}**`,
                  analyze_wildcard: false,
                  default_field: "ADMINCODE",
                },
              },
            ],
            should: [],
          },
        },
      };
      // let match_phrase = {
      //   match_phrase: {},
      // };
      // //输入字符串不分词;
      // match_phrase.match_phrase["NAME"] = {};
      // match_phrase.match_phrase["NAME"].query = `${inputStr}`;
      // match_phrase.match_phrase["NAME"].slop = 0;
      // querydata.query.bool.must.push(match_phrase);
      // match_phrase = {
      //   match_phrase: {},
      // };
      // //输入字符串不分词
      // match_phrase.match_phrase["ADDRESS"] = {};
      // match_phrase.match_phrase["ADDRESS"].query = `${inputStr}`;
      // match_phrase.match_phrase["ADDRESS"].slop = 0;
      // querydata.query.bool.must.push(match_phrase);
      // let multi_match = { multi_match: {} };
      // multi_match.multi_match["query"] = inputStr;
      // multi_match.multi_match["fields"] = [`NAME`, "ADDRESS"];
      // multi_match.multi_match["operator"] = "or";
      // multi_match.multi_match["minimum_should_match"] = "100%";
      // querydata.query.bool.must.push(multi_match);
      return querydata;
    },
  },
};
